package com.qf.controller;

import com.qf.pojo.Product;
import com.qf.service.ProductService;
import com.qf.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * 访问前台主页
 */
@WebServlet("/index")
public class IndexServlet extends BaseServlet {

    /**
     * 跳转到主页
     * @param request
     * @param response
     */
    public void index(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        //调用ProductService商品的业务接口
        //获取最新商品和热门的商品信息---->List<Product>
        ProductService productService = new ProductServiceImpl() ;
        List<Product> newList = productService.getNewProducts();
        List<Product> hotList = productService.getHotProducts();
        if(newList!=null && hotList!=null){
            //存储在request 域汇总
            request.setAttribute("newList",newList);
            request.setAttribute("hotList",hotList);
            //请求转发
            request.getRequestDispatcher("/jsp/index.jsp").forward(request,response);
        }

    }
}
